#include "SubsystemAdaptor.h"

#if defined NZOS_WIN32
#	include <Windows.h>
#elif defined NZOS_ANDROID

#elif defined NZOS_IOS
#   include "macUtils.h"
#endif

namespace Nezha
{

	DynamicLibary::DynamicLibary()
		:mHandle(NULL)
	{

	}

	DynamicLibary::~DynamicLibary()
	{

	}

	bool DynamicLibary::load(const _string& name)
	{
		mName = name;

#if defined NZOS_WIN32
		if (mName.substr(mName.length() - 4, 4) != ".dll")
			mName += ".dll";
#elif defined NZOS_ANDROID
		if (mName.find(".so") == String::npos)
			mName += ".so";
#elif defined NZOS_IOS
		if (mName.substr(mName.length() - 6, 6) != ".dylib")
			mName += ".dylib";
#endif

		mHandle = (DYNLIB_HANDLE)DYNLIB_LOAD(mName.c_str());

		return mHandle != NULL;

	}

	void DynamicLibary::unload()
	{
		DYNLIB_UNLOAD(mHandle);
	}

	void* DynamicLibary::getProcAddress(const _string& procName)
	{
		return (void*)DYNLIB_GETENTRY(mHandle, procName.c_str());
	}
	
	const _string SubsystemAdaptor::msCreateEntryName = "NezhaPluginCreate";
	const _string SubsystemAdaptor::msDestroyEntryName = "NezhaPluginDestroy";

}//end namespace Nezha
